module HomeHelper
	def set_active(page, current)
		pageArray = page.split(',')

		checkHaveIn = false	
		pageArray.each do |page|
			if page == current
				return "class='active'"
			end
		end

		if checkHaveIn == false
			return ""
		end
		
	end

	def set_sidebar
		if session[:login].nil?
			render "user/login"
		else
			render :partial => "user/info", :locals => {:avatar => @avatar}
		end
	end

	def set_header
		if session[:login].nil?
			html = '<ul class="nav">'
			html+= "<li  #{set_active('home',@page)} >"
			html+=	link_to "Home", root_path 
			html+=	"</li>"
			html+=	"<li #{set_active('signup',@page)} >"
			html+=	link_to "Sign Up", signup_path
			html+=	"</li>"
			html+=	"</ul>"
		else
			html = '<ul class="nav">'
			html+= "<li  #{set_active('home',@page)} >"
			html+=	link_to "Home", root_path 
			html+=	"</li>"
			html+= "<li  #{set_active('user,profile',@page)} >"
			html+=	link_to "Page", user_path 
			html+=	"</li>"
      if !session[:admin].nil?
        html+= "<li  #{set_active('AdminManage',@page)} >"
        html+=	link_to "Manage", admin_home_path
        html+=	"</li>"
      end
      html+=	"</ul>"
			html+=    '<div class="btn-group" style="float:right;">'
			html+=		link_to session[:login], user_path , :class => "btn"
			html+=	   '<button class="btn dropdown-toggle" data-toggle="dropdown">'
			html+=	   '<span class="caret"></span>'
			html+=	   '</button>'
			html+=	   '<ul class="dropdown-menu">'
			html+=		"<li>"
			html+=		link_to "Edit Profile", profile_path
			html+=		"</li>"
			html+=		"<li>"
			html+=		link_to "Sign Out", logout_path
			html+=		"</li>"
			html+=	   '</ul>'
			html+=    '</div>'
      
		end
		raw html
	end

	def change_date (date)
		date.getlocal.strftime("%I:%M%p - %d/%m/%Y")
	end

	def show_date(created, updated, id, style = 1)
		if created == updated
			html = "<small style='float:right;'><i id='date_#{id}'></i></small>"
			html += "<small style='float:right;'>Post At : #{change_date(created)}</small>"
		else
			html = "<small style='float:right;'><i id='date_#{id}'>&nbsp;&nbsp;&nbsp;(Edit At : #{change_date(updated)}) </i></small>"
		    html +="<small style='float:right;'>Post At : #{change_date(created)}</small>"
		end
		if style == 1
			raw html
		else
			html
		end
	end

	def this_owner? (username, id, style = 1)
		if session[:login] == username
			image_edit = '<img src="/images/edit.png" alt="" width="20" />'
			image_delete = '<img src="/images/delete.png" alt="" width="20" />'
			html = '<div style="float:right;">'
			html+= "<a href='javascript:;' onclick='show_edit_post(#{id})'>" + image_edit + '</a>'
			html+= " "
			html+= '<a href="' + delete_post_path(id) + '" onclick="return confirm(\'Are you sure ?\')">' + image_delete + '</a>'
    		html+=  '</div>'
		end
		if style == 1
			raw html
		else
			html
		end
	end

  def set_comment (imgUrl, username, user_id, id, style = 1)
    if !session[:login].nil?
      html = "<br/>"
      html += "<textarea rows='1' style='width:98.7%' rel='#{id}' id='box_comment'" + 
      "dest='#{add_comment_path}' imgsrc='#{imgUrl}' username='#{username}' userid='#{user_id}'></textarea>"
      html += "<div style='display:none;text-align:center' id='loading#{id}'><img src='images/ajax-loader.gif' alt='' width='43' height='11'/></div>";
    end
	if style == 1
		raw html
	else
		html
	end
  end
end
